<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>运费列表-增加</title>
	<link rel="stylesheet" type="text/css" href="../resource/css/base.css" />
	<script type="text/javascript" src="../resource/js/popup/popup.js"></script>
	<script type="text/javascript" src="../resource/js/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="../resource/js/prototype.js"></script>
	<s:actionmessage/>
	<script type="text/javascript">
		function $$(name){return document.getElementsByName(name)[0];}
		function $id(name){return document.getElementById(name);}
		function openWin(title,action){
			if(action == 'loadOrder'){
				action += ".action";
				var clientId = $$("clientId").value;
				if(clientId.length <= 0){
					alert("请先选择客户.");
					return;
				}
				action += "?clientId=";
				action += clientId;
			}
			ShowIframe(title, action, 750, 500);
		}
		function setForm(data){
			document.forms[0].reset();
			$id("linkMan").innerText = $id("phone").innerText = "";
			$id("totalFee").innerText = $id("totalPayFee").innerText = "";
			$id("leftOweFee").innerText = "";
			try{
				$$("clientName").value = data["items"][0]["cols"][2];
				$$("clientId").value = data["items"][0]["id"];
				$id("linkMan").innerText = data["items"][0]["cols"][1];
				$id("phone").innerText = data["items"][0]["cols"][4];
			}catch(e){
				alert(e.name + ":" + e.message);
			}
		}
		//订单信息
		function setOrderInfo(data){
			try{
				$$("orderId").value = data[0]["id"];
				$id("totalFee").innerText = data[0]["totalFee"];
				$id("totalPayFee").innerText = data[0]["totalRealPayFee"];
				$$("oweFee").value = Number(data[0]["totalFee"]) - Number(data[0]["totalRealPayFee"]);
			}catch(e){
				alert(e.name + ":" + e.message);
			}
		}
		
		function setNextCharge(obj){
			$id("leftOweFee").innerText = Number($$("oweFee").value) - Number(obj.value);
			$$("nextChargeFee").value = Number($$("oweFee").value) - Number(obj.value);
		}
		
		function sumbit(){
			var form = document.forms[0];
			var pattern = /^[0-9]+(\.[0-9]{1,2}){0,1}$/;
			
			if($$("realPayFee").value==0){
				alert("请输入收费金额.");
				return false;
			}
			if(!pattern.test($$("realPayFee").value)){
				alert("付费金额数据格式不正确,请重新填写.");
				return false;
			}
			if($$("chargeDate").value==""){
				alert("请输入收费日期.");
				return false;
			}
			if($$("nextChargeFee").value==""){
				alert("请输入欠费金额.");
				return false;
			}
			if($$("nextChargeDate").value==""&&$$("nextChargeFee").value!=0){
				alert("请输入下次缴费日期.");
				return false;
			}
			form.action="add.action";
			form.submit();
		}
	</script>

</head>
<body  oncontextmenu="return false;" leftmargin="8" topmargin="8">
<div class="tip"><span>当前位置:</span>运费管理&nbsp;&gt;&nbsp;新增&nbsp;&gt;&nbsp;</div>
<s:form name="add" namespace="/chargeRecord">
<s:hidden name="clientId"/>
<s:hidden name="oweFee"/>
<table id="infoTab" class="edittb" cellpadding="2" cellspacing="1">
	<tr bgcolor="#EEF4EA">
		<td height="35" colspan="6">&nbsp;运费信息&nbsp;</td>
	</tr>
	<tr>
		<td class="coln" width="15%">客户名称</td>
		<td width="30%" class="colv" nowrap="nowrap">
			<s:textfield name="clientName" readOnly="readonly"/>
			<img src="../resource/image/menusearch.gif" onclick="openWin('客户查询','../invoiceOrder/popupLoadClient');" style="cursor: pointer">
		</td>
		<td class="coln" width="15%">联 系 人</td>
		<td width="30%" class="colv" id="linkMan">&nbsp;</td>
		<td class="coln" width="15%">联系电话</td>
		<td width="30%" class="colv" id="phone">&nbsp;</td>
	</tr>
	<tr>
		<td class="coln" width="15%">运货单号</td>
		<td width="30%" class="colv" nowrap="nowrap">
			<s:textfield name="orderId" readOnly="readonly"/>
			<img src="../resource/image/menusearch.gif" onclick="openWin('运货单查询','loadOrder','clientId='+$$('clientId').value);" style="cursor: pointer">
		</td>
		<td class="coln">总 运 费</td>
		<td class="colv"><span id="totalFee">0.00</span>元</td>
		<td class="coln">已付运费</td>
		<td class="colv"><span id="totalPayFee">0.00</span>元</td>
	</tr>
	<tr>
		<td class="coln"><SPAN style="color: red">*</SPAN> 本次收费金额</td>
		<td class="colv">
			<s:textfield name="realPayFee" onblur="setNextCharge(this);"/>元
		</td>
		<td class="coln"><SPAN style="color: red">*</SPAN> 本次收费日期</td>
		<td  class="colv">
			<s:textfield onclick="WdatePicker();" cssClass="Wdate" name="chargeDate"></s:textfield>
		</td>
		<td class="coln"> 未支付金额</td>
		<td class="colv"><span id="leftOweFee">0.00</span>元</td>
	</tr>
	<tr>
		<td class="coln"><SPAN style="color: red">*</SPAN> 预约付费金额</td>
		<td class="colv">
			<s:textfield name="nextChargeFee"/>元
		</td>
		<td class="coln"><SPAN style="color: red">*</SPAN> 预约付费日期</td>
		<td class="colv">
			<s:textfield onclick="WdatePicker();" cssClass="Wdate" name="nextChargeDate"></s:textfield>
		</td>
		<td class="colv" colspan="2"></td>
	</tr>
	<tr>
		<td class="coln">备注</td>
		<td colspan="5" class="colv">
			<s:textarea name="note"></s:textarea>
		</td>
	</tr>
	<tr align="right" bgcolor="#EEF4EA">
		<td height="35" colspan="6" align="center">
			<a href="javascript:history.go(-1)" class="coolbg">&nbsp;返&nbsp;回&nbsp;</a>
			<a href="#" class="coolbg" onclick="return sumbit();">&nbsp;保&nbsp;存&nbsp;</a>
			<a href="javascript:document.forms[0].reset()" class="coolbg">&nbsp;重&nbsp;置&nbsp;</a>
		</td>
	</tr>
</table>
</s:form>
</body>
</html>
